package NM;

public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val){
            this.val=val;
        }
    }
    public ListNode first=null;
    public ListNode last=null;
    public int usedSize=0;
    //添加队列；；
    public void offer(int val){
        ListNode node=new ListNode(val);
        if(isEmpty()){
            first=last=node;
        }else{
            last.next=node;
            node.prev=last;
            last=last.next;
        }
        usedSize++;

    }
    //如果是空队例的情况；
    public boolean isEmpty(){
        return usedSize==0;
    }
//出队列；
    public int pop(){
        if(isEmpty()){
            return -1;
        }
        int val= first.val;
        first=first.next;
        if(first==null){
            first.prev=null;
        }
        usedSize--;
        return val;
    }
    //获取队例元素；
    public int peek(){
        if(isEmpty()){
            return -1;
        }
        return first.val;
    }
}
